Skip to content

Extras: notify, transient toasts and a persistent notice stack - #382

Merged
samitbasu merged 4 commits into
mainfrom
notify-347
Nov 20, 2026
Merged

samitbasu merged 4 commits into
mainfrom
notify-347

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Part of #347. Stacked on #369 (NodeHandle::live). Until #369 merges, this diff also shows that PR's commit (src/builder.rs, tests/it/interaction.rs).

This is PR 2 of the design note's split: the notify feature of eggshell-ui-extras, built only on core's public API, following the decisions comment.

The look is not final. The cards use a private default taken from the core style (the menu's popover surface at sonner's sizes), and the action and × buttons use the style's default variant. NotifyStyle, its shadcn values behind eggshell-ui-shadcn/extras and an example come in PR 3, after the user picks from the render round.

API for review

// eggshell_ui_extras::notify (feature "notify")
pub struct NoticeId(u64);             // new(u64), From<u64>, Into<u64>
pub enum NoAction {}                  // the Act of a notice without actions
pub struct Notice<Act = NoAction> { pub id: NoticeId, pub text: String, pub actions: Vec<NoticeAction<Act>> }
pub struct NoticeAction<Act> { pub label: String, pub act: Act }
impl<Act> Notice<Act> {
    pub fn new(id: impl Into<NoticeId>, text: impl Into<String>) -> Self;
    pub fn action(self, label: impl Into<String>, act: Act) -> Self;
}
pub enum Lifetime { Dwell(Duration), UntilDismissed }
pub enum Dismissed { Expired, Closed, Escape }
pub enum ScreenAnchor { TopLeft, TopCenter, TopRight, BottomLeft, BottomCenter, BottomRight }
impl ScreenAnchor { pub fn placement(self, inset: Distance) -> Placement; }

pub trait NotifyExt<'b, 'f, A> {
    fn notifications<K: Key + Clone, Act: Clone + 'static>(&mut self, key: K, items: &[Notice<Act>])
        -> Notifications<'_, 'b, 'f, A, K, Act>;
}
impl Notifications<..> {
    pub fn at(self, anchor: ScreenAnchor, inset: Distance) -> Self; // default BottomRight, 24
    pub fn lifetime(self, lifetime: Lifetime) -> Self;              // default UntilDismissed
    pub fn closable(self) -> Self;                                  // × on a Dwell stack
    pub fn named(self, name: impl Into<String>) -> Self;            // default "Notifications"
    pub fn on_action(self, f: impl Fn(&mut A, NoticeId, Act) + 'static) -> Self;
    pub fn on_dismiss(self, f: impl Fn(&mut A, NoticeId, Dismissed) + 'static) -> Self;
    pub fn add(self);
}

Behaviour

  • Queue. The application owns the queue. app.toast.as_slice() (an Option) means a new notice replaces the old one; a Vec stacks them. The newest notice sits nearest the anchor. The library never adds or removes notices; it calls the handlers.
  • Dwell. Each visible id gets its own Duration dwell on egui's clock, computed by a pure Dwell::tick(now, length, Hold) (unit-tested), and a repaint is booked for the next expiry.
    • The dwell pauses while the pointer is over the stack, while focus is inside it, or while the window is unfocused. Paused time does not count.
    • A new id starts a fresh dwell.
    • A notice that the handler does not remove gets Expired only once.
  • Esc dismisses a notice only while focus is inside it. The widget remembers focus across the pass in which egui drops focus for the Esc.
  • × button. It is off on toasts unless closable() is set, and always shown on UntilDismissed notices. Its name is "Dismiss: ".
  • Actions are buttons. They leave the notice up.
  • Live region. The stack is a named Role::Status node with live(Polite).
  • Overlay. The stack is drawn in a Band::Popup overlay with Focus::None, DismissOn::Never and Outside::PassThrough. It sits above an open dialog and still takes clicks.
  • Placement is Placement::edge(side).align(..) inside Boundary::Window.inset(Sides::all(inset)). The rect comes from the existing placed.overlay(key).rect().
  • No entrance motion in v1.

Tests (tests/it/notify.rs, through the rig, stepped clock)

  • a_toast_expires_after_its_dwell_on_the_stepped_clock
  • a_running_dwell_books_a_repaint_for_its_expiry: idle page → Duration::MAX; with a toast → the remaining dwell
  • the_dwell_holds_while_the_pointer_is_over_the_stack
  • the_dwell_holds_while_focus_is_inside_and_while_the_window_is_in_the_background
  • a_replacement_keeps_one_toast_and_starts_its_own_dwell
  • a_persistent_notice_never_expires_and_newest_sits_nearest_the_top_anchor
  • esc_dismisses_a_notice_only_while_focus_is_inside_it
  • the_close_button_dismisses_its_notice
  • a_toast_has_no_close_button_unless_asked
  • an_action_button_runs_on_action_and_leaves_the_notice_up
  • a_stack_is_a_polite_status_region_by_its_name
  • the_stack_follows_its_inset_and_its_rect_is_queryable
  • a_notice_floats_above_an_open_dialog_and_takes_the_pointer
  • notify::dwell unit tests: counting down, holding and resuming, a clock that goes back

Known gaps (core-side, not changed here)

  • Esc over an open dialog. Core sends Esc to the topmost overlay that accepts Esc, which is the dialog, before any draw closure runs. With focus in a notice above an open dialog, Esc closes the dialog instead of the notice. The window's cancel button takes Esc the same way.
  • Live region lifetime. The live region exists only while the stack is non-empty, because the overlay is declared only then. The manual screen-reader check is planned for PR 3.

Behaviour changes

None. The feature is new and opt-in.

cargo xtask ci: exit 0 on this head, merged with current main. One earlier full run segfaulted in the screenshots step (lavapipe, SIGSEGV) while the machine was under load. The same step passed 4/4 standalone and 3/3 through xtask ci with the other steps skipped, and the rerun of the full CI exited 0.

The UI trial waits for PR 3, where the look lands.

🤖 Generated with Claude Code

samitbasu and others added 2 commits November 18, 2026 10:04
Both consumers hand-build a toast slot and a notice stack (#347). The
notify feature gives them one widget on core's public API:

- The queue is the application's: `notifications(key, &[Notice])` takes
  `Option::as_slice` for a slot a new notice replaces, or a `Vec` for a
  stack, newest nearest the anchor. Expiry, the ×, Esc and actions come
  back through `on_dismiss(app, id, Dismissed)` and `on_action`.
- `Lifetime::Dwell(Duration)` per stack, on egui's clock: the library keeps
  only each visible id's dwell, ticked by a pure `Dwell` (the tooltip's
  pattern), and books a repaint for the next expiry. It holds while the
  pointer is over the stack, focus is inside it, or the window is in the
  background. A new id starts afresh; an expired notice fires once.
- Esc dismisses a notice only while focus is inside it, remembered across
  the pass in which egui drops the focus for the Esc.
- Toasts show a × only with `closable()`; `UntilDismissed` notices always
  do. Actions are buttons and leave the notice up.
- The stack is a named `Status` node with a polite live region
  (`NodeHandle::live`), in a `Band::Popup` overlay that takes no focus,
  never dismisses itself and passes outside presses through, so it sits
  above dialogs and stays clickable.
- `ScreenAnchor` plus a `Distance` inset is a thin constructor of core's
  `Placement::edge(..).align(..)` with an inset window boundary; the rect
  is the existing `placed.overlay(key).rect()`.

The look is a private default derived from the core style (the menu's
popover surface at sonner's sizes) until the render round picks the
NotifyStyle; no shadcn values and no entrance motion yet.

Part of #347.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AJYxo4YJZUXcPJ1bHdAHKy
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user after the notifications trial (2026-11-19). GitHub's required checks pass on the branch merged with current main. Merging.

@samitbasu
samitbasu merged commit a4d2f99 into main Nov 20, 2026
4 checks passed
samitbasu added a commit that referenced this pull request Nov 20, 2026
#382 added notify's tests on the old rig, using Rig::observe, which this
branch deleted as unused. Like badge, hover_anchored, hover_card and
refused, notify stays on the rig for now, and observe comes back for it.
Outcomes: 2386, none failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant